package com.lagou.edu.controller;

import com.lagou.edu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangjinshan
 * @version 1.0
 * @description
 * @date 2021/8/25 下午6:19
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 注册
     * @param email
     * @param password
     * @param code
     * @return
     */
    @GetMapping("/register/{email}/{password}/{code}")
    public Integer register(@PathVariable(name = "email") String email, @PathVariable(name = "password") String password, @PathVariable(name = "code") String code){
        return userService.register(email, password, code);
    }

    /**
     * 判断邮箱是否注册
     * @param email
     * @return
     */
    @GetMapping("/isRegistered/{email}")
    public boolean isRegistered(@PathVariable(name = "email") String email){
        return userService.isRegister(email);
    }

    /**
     * 登录
     * @param email
     * @param password
     * @return
     */
    @GetMapping("/login/{email}/{password}")
    public String login(@PathVariable(name = "email") String email, @PathVariable(name = "password") String password){
        return userService.login(email, password);
    }

    /**
     * 根据token查询⽤用户登录邮箱接⼝口
     * @param token
     * @return
     */
    @GetMapping("/info/{token}")
    public String info(@PathVariable(name = "token") String token){
        return userService.info(token);
    }
}
